﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ConnectToDatabase;
using ConnectToDatabase.Model;

namespace QLGiayDep.Forms
{
    /// <summary>
    /// Interaction logic for FormDSNhanVien.xaml
    /// </summary>
    public partial class FormDSNhanVien : Page
    {
        //private ShowDB showDB;
        private UpdateDB updateDB;
        private SelectDB selectDB;
        private bool m_bSelectData = false;
        //private bool m_bSelectCombo = false;
        string URL;

        public FormDSNhanVien(string _URL)
        {
            InitializeComponent();
            URL = _URL;
            selectDB = (SelectDB)Activator.GetObject(typeof(SelectDB), URL + "SELECTDB_OBJECT");
            updateDB = (UpdateDB)Activator.GetObject(typeof(UpdateDB), URL + "UPDATEDB_OBJECT");
            dataDSNhanVien.ItemsSource = selectDB.SelectAllDSNhanVien();
        }

        //cap nhat lai tinh trang bang 0
        private void btnNghiViec_Click(object sender, RoutedEventArgs e)
        {
            updateDB = (UpdateDB)Activator.GetObject(typeof(UpdateDB), URL + "UPDATEDB_OBJECT");
            updateDB.UpdateNhanVien(txtMaNV.Text, 0);
            m_bSelectData = true;
            dataDSNhanVien.ItemsSource = selectDB.SelectAllDSNhanVien();
        }

        private void dataDSNhanVien_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!m_bSelectData)
            {
                var item = dataDSNhanVien.SelectedItem as NhanVien;
                txtMaNV.Text = item.MaNhanVien.ToString();
             
                txtHoTen.Text = item.TenNhanVien.ToString();
            }
            else
            {
                m_bSelectData = false;
                //m_bSelectCombo=false;
            }
        }
    }
}
